<!-- 增加页面开始 -->

[#macro businesscircleAddView]
<div class="model-form">
	<el-page-header @back="goBack" content="增加商圈">
	</el-page-header>
	<div class="model-content">
		<el-form ref="ruleForm" :rules="rules" :model="form" label-width="160px">
			<el-row :gutter="10">
				<el-col :span="22">
					<el-form-item label="商圈名称" size="mini" prop="name">
						<el-input v-model="form.name" name="name">
						</el-input>
					</el-form-item>

				</el-col>
				<el-col :span="22">
					<el-form-item label="中心地址" size="mini" prop="address">
						<el-input v-model="form.address" name="address">
							<template slot="append">
								<el-button type="primary" size="small" @click="geo">定位</el-button>
							</template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="22">
					<el-form-item label="地图信息" size="mini">
						<nb-map zoom="18" @poi-change="changePoi" :lat="form.lat" :lng="form.lng"></nb-map>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="22" style="text-align: right;padding-bottom: 20px;padding-top: 20px;">
					<el-button @click="goBack">取消</el-button>
					<el-button type="primary" @click="add">确定</el-button>
				</el-col>
			</el-row>
		</el-form>
	</div>
</div>
[/#macro]

[#macro businesscircleAddConfig]
<script type="text/x-template" id="my-businesscircle-add">
	[@businesscircleAddView /]
</script>
<script type="text/javascript">
	//添加组件开始
	var businesscircleAddConfig = {};
	businesscircleAddConfig.template = "#my-businesscircle-add";
	businesscircleAddConfig.methods = config.basicMethod();
	businesscircleAddConfig.data = function () {
		return {
			form: {
				name: '',
				address: '',
				lat:"",
				lng:""
			},
			rules: {
				name: [
					{ required: true, message: '请输入商圈名称', trigger: 'blur' }
				],
				address: [
					{ required: true, message: '请输入中心地址', trigger: 'blur' }
				]
			}
		}
	};
	businesscircleAddConfig.mounted = function () {
		
		this.form.lat=34.33504;
		this.form.lng=108.94778;
		console.info(this.form);
	}
	businesscircleAddConfig.computed = {};


	businesscircleAddConfig.methods.add = function () {
		var self = this;
		this.$refs["ruleForm"].validate(function (valid) {
			if (valid) {
				self.addData();
			} else {
				console.log('error submit!!');
				return false;
			}
		});
	}
	businesscircleAddConfig.methods.changePoi = function (event) {
        console.log(event);
        this.form.lat = event.lat;
        this.form.lng = event.lng;

    }
	businesscircleAddConfig.methods.geo = function (event) {
        var param = {};
        param.address = this.form.address;
        var self = this;
        this.postData("${siteurl}tenantRest/area/lbs.htm", param, function (result) {
            if (result.code == 0) {
                self.form.lat = result.lat;
                self.form.lng = result.lng;
                if(result.provinceId){
                    self.form.province=result.provinceId;
                }
                if(result.cityId){
                    self.form.city=result.cityId;
                }
                if(result.countyId){
                    self.form.area=result.countyId;
                }
            }
        });

    }
	businesscircleAddConfig.methods.addData = function () {
		var self = this, data = this.form;
		if (this.deforeAddData) {
			this.deforeAddData();
		}
		this.postData("${siteurl}tenantRest/businesscircle/create.htm", data, function (res) {
			if (res.code == 0) {
				self.$message({
					message: '添加数据成功',
					type: 'success'
				});
				self.$router.go(-1);
			} else {
				self.$message.error(res.msg);
			}
		});
	}

	businesscircleAddConfig.destroyed = function () {
		console.log("destroyed add view ");

	}
	var businesscircleAddView = Vue.component('add-view', businesscircleAddConfig);


</script>
[/#macro]

<!-- 增加页面结束 -->